package com.task.dao.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.hibernate.Query;
import org.hibernate.Session;

import com.task.common.BaseHibernateDao;
import com.task.dao.ExperienceDao;
import com.task.entity.Experience;

public class ExperienceDaoImpl extends BaseHibernateDao<Experience> implements
		ExperienceDao {

	public Experience getExperienceByDate(Integer userId, String date11) {
		    SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd");
			Date date=null;
			try {
				date = sim.parse(date11);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			Date   tommorow   =   new   Date(date.getTime()+24*60*60*1000);
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd 00:00:00");
		    Session session=super.getSession();
			String hql="select expe from Experience expe where expe.user.userId=:id and expe.experienceDate >= '"+sdf.format(date)+"' and expe.experienceDate < '"+sdf.format(tommorow)+"'";
			Query query=session.createQuery(hql);
			query.setInteger("id", userId);
			return (Experience)query.uniqueResult();
	}

	public Integer addExperience(Experience experience) {
		return (Integer) super.add(experience);
	}

}
